{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Number of Ways to Climb Stairs\n",
    "\n",
    "[The Original Question](https://mp.weixin.qq.com/s/eisCbDIR6oVtRblAF3P2XA)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question\n",
    "\n",
    "You are given a positive integer `N` which represents the number of steps in a staircase. You can either climb 1 or 2 steps at a time. Write a function that returns the number of unique ways to climb the stairs.\n",
    "\n",
    "**Challenge**: Can you find a solution in $O(n)$ time?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "def stair_case(N):\n",
    "    \"\"\" Dynamic Programming Algorithm \"\"\"\n",
    "    ways = [0] * (N + 1)\n",
    "    if ways[N] != 0:\n",
    "        return ways[N]\n",
    "    if N <= 0:\n",
    "        return 0\n",
    "    elif N == 1:\n",
    "        ways[N] = 1\n",
    "        return ways[N]\n",
    "    elif N == 2:\n",
    "        ways[N] = 2\n",
    "        return ways[N]\n",
    "    ways[N] = stair_case(N - 1) + stair_case(N - 2)\n",
    "    return ways[N]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n",
      "8\n"
     ]
    }
   ],
   "source": [
    "print(stair_case(4))\n",
    "print(stair_case(5))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
